package com.longcai.piaojia.widget;

import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.EditText;

/**
 * Created by Administrator on 2016/9/28.
 */
public class NoSpaceStartEditText extends EditText {

    public NoSpaceStartEditText(Context context) {
        super(context);
        init();
    }

    public NoSpaceStartEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public NoSpaceStartEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){

        setFilters(new InputFilter[]{filter});

    }

    private InputFilter filter=new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            if(TextUtils.isEmpty(getText().toString())&&source.toString().equals(" "))return "";
            else return null;
        }
    };

}
